package com.cecsmsserve.controller;

import com.cecsmsserve.util.result.CommonResult;
import com.cecsmsserve.util.upload.FileUploadInfo;
import com.cecsmsserve.util.upload.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@CrossOrigin
@RestController
@RequestMapping("/upload")
public class FileController {

    @Autowired
    private FileUploadInfo fileUploadInfo;

    /***
     * 上传文件
     * @param file
     * @return
     */
    @RequestMapping("/file")
    public CommonResult uploadFile(@RequestParam("file") MultipartFile file) {
        //使用配置的上传的文件存储基础路径
        String basePath = fileUploadInfo.getImageBasePath();
        return FileUploadUtils.upload(file, basePath,"file");
    }

    /***
     * 上传图片
     * @param imageFile
     * @return
     */
    @RequestMapping ("/image")
    public CommonResult uploadImage(@RequestParam("imageFile")MultipartFile imageFile){
        //使用配置图片的文件存储基础路径
        //basePath:    e:/whx/0GraduationProject/cecsms
        String basePath = fileUploadInfo.getImageBasePath();
        System.out.println("imageFile:"+imageFile);
        return FileUploadUtils.upload(imageFile, basePath,"image");
    }


    /***
     * 上传视频
     * @param videoFile
     * @return
     */
    @RequestMapping("/video")
    public CommonResult uploadVideo(@RequestParam("videoFile") MultipartFile videoFile){
        //使用配置视频的文件存储基础路径
        return FileUploadUtils.upload(videoFile, fileUploadInfo.getImageBasePath(),"video");
    }

}
